# coding:utf-8
 
import json,os,thread
from wsgiref.simple_server import make_server
 
 
# 定义函数，参数是函数的两个参数，都是python本身定义的，默认就行了。
def application(environ, start_response):
    # 定义文件请求的类型和当前请求成功的code
    start_response('200 OK', [('Content-Type', 'application/json')])
    # environ是当前请求的所有数据，包括Header和URL，body
 
    request_body = environ["wsgi.input"].read(int(environ.get("CONTENT_LENGTH", 0)))
    request_body = json.loads(request_body)
 
    cmd = request_body["cmd"]

 
    #if cmd=='updatepic':
        #thread.start_new_thread( updatepic() )
        
 
    dic = {'msg':'successful','yourCmdIs': cmd}
 
    return [json.dumps(dic)]
 
def updatepic():
    os.popen('python getmeteopic.py')
 
if __name__ == "__main__":
    port = 9991
    httpd = make_server("0.0.0.0", port, application)
    print "serving http on port {0}...".format(str(port))
    httpd.serve_forever()
